<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      /** 方法一
       * @param {string} s
       * @param {string} t
       * @return {character}
       */
      var findTheDifference = function (s, t) {
        const res1 = s.split("").sort().join("");
        const res2 = t.split("").sort().join("");

        for (let i = 0; i < t.length; i++) {
          if (res1[i] != res2[i]) {
            return res2[i];
          }
        }
      };

      /** 方法二
       * @param {string} s
       * @param {string} t
       * @return {character}
       */
      var findTheDifference = function (s, t) {
        if (!s.length) return t;
        let sum1 = 0,
          sum2 = 0,
          i = 0;
        while (i < t.length) {
          if (s[i]) sum1 += s.charCodeAt(i);
          if (t[i]) sum2 += t.charCodeAt(i);
          i++;
        }
        return String.fromCharCode(sum2 - sum1);
      };
    </script>
  </body>
</html>
